package com.rad.ip.discovery.config;

import com.google.common.net.HostAndPort;
import com.orbitz.consul.Consul;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Date:  2018/5/21
 * Time:  16:01
 * Email: siy@hmgsoft.com
 * Created by siy
 */
@Configuration
public class ConsulConfig {
    @Value("${ip-discovery.consul.ip}")
    private String ip;
    @Value("${ip-discovery.consul.port}")
    private int port;

    @Bean
    public Consul createConsul(){
        HostAndPort hostAndPort = HostAndPort.fromParts(ip,port);
        Consul client = Consul.builder()
                .withConnectTimeoutMillis(3000)
                .withPing(true)
                .withReadTimeoutMillis(2000)
                .withWriteTimeoutMillis(2000)
                .withHostAndPort(hostAndPort).build();
        return client;
    }

}
